package com.museum.demo.TokenManager;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import javax.xml.crypto.Data;
import java.util.Date;

@Component
public class TokenCreate {

    /*
    * function: 生成token
    * user: 马山林
    * date: 2021.1.28
    * */
    public String GenerateToken(String username,String psw) {
        Date start = new Date();
        long currentTime = System.currentTimeMillis()+60*60*1000; //一小时有效时间
        Date end = new Date(currentTime);
        String token = "";

        token = JWT.create()
                .withAudience(username)
                .withIssuedAt(start)
                .withExpiresAt(end)
                .sign(Algorithm.HMAC256(psw));
        return token;
    }
}
